<template>
	<view>
		<u-button type="warning" @click="handleEmpower" text="确定授权"></u-button>
	</view>
</template>

<script>
	import {
		https
	} from '../../utils/request.js'
	export default {
		data() {
			return {
				appid: 'wxee65cd1d8d361e58',
				secret: 'ce9582ed8c1faf4c6a950c13273b38e7'
			};
		},
		methods: {
			// 授权
			handleEmpower() {
				let test = this
				console.log(111);
				uni.getUserProfile({
					desc: '登录',
					success(res) {
						console.log(19, res);
						let {
							nickName,
							avatarUrl
						} = res.userInfo
						uni.login({
							success(res1) {
								console.log(25, res1);
								let {
									code
								} = res1
								https({
									url: '/wx_login',
									data: {
										code,
										appid: test.appid,
										secret: test.secret,
										nickName,
										avatarUrl
									},
									method: 'post'
								}).then(res2 => {
									console.log(48, res2);
									uni.setStorageSync('token', res2.data.data.user_Token)
									uni.setStorageSync('image', res2.data.data.avatarUrl)
								})
							}
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">

</style>